<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\components;
use yii\base\Widget;
use Yii;
use app\components\Fun;
use app\models\Showcase;
/**
 * Description of ZgfWidget
 *
 * @author shuai
 */
class HomeWidget extends  Widget{
    /**
     * 表示加载完成了
    */
    const Load_END='end';
    
    
    static $_model=null;
    static  public function model(){
        if(self::$_model===null){
           self::$_model=new HomeWidget(); 
        }
        return self::$_model;
    }
     

    /**
     * 加载云音乐环境片段
  */
  public static function iframeMusic(){
      ////只有云音乐环境才调用自动登录接口
      if(Lcms::get_browser()!==Lcms::APP_music||!Yii::$app->user->isGuest){
          return '';
      }
      
      
      return '<iframe src="http://music.163.com/static/proxy.html" onload="iframe_load()" style="display: none" class="hidden" id="proxy"></iframe>';
  }

  public function render($view, $params = [])
    {
       
       return  parent::render('@app/components/home/'.$view, $params);       
    }
     
   /**
    * 显示一批评论
    */ 
    public function showlist($cid){
        return $this->render('pinglun',['cid'=>$cid]);
    }
    /**
     * 显示一条评论
     */
    public function getPinglunLi($model){
        return $this->render('pinglunli',['model'=>$model]);
    }
    
    /**
     * 显示一个案例
    */
   public function renderCaseLi($vo){
       return $this->render('CaseLi',['vo'=>$vo]);
   }
   
   const LimitCount=5;
   /**
    * 显示一组案例
   */
   public function renderCase($page=0){
       $cachaKey='renderCase'.$page;
       $cache=Yii::$app->cache->get($cachaKey);
       if($cache){
           return $cache;
       }
       $limit=self::LimitCount;
       $find= Showcase::find();//->orderBy('id DESC')->all();
       $find->where('display=1');
       $find->limit($limit);
       $find->orderBy('id DESC');
       $find->offset($limit*$page);
       $list=$find->all();
       $html='';
       foreach ($list as $vo) {
           $html.=$this->renderCaseLi($vo);
       }
       Yii::$app->cache->set($cachaKey, $html,30);
       return $html;
   }
}

